import { ref, watch } from 'vue'
import Api from '@/api'

export default function useAnnotation(id){
    const slideId = ref(null)
    const annotationList = ref([])

    watch(slideId, async (val) => {
        if(!val) return
        const pre = Api.getPresetAnnotationList({
            slideId: val,
            page: 1,
            pageCnt: 1000
        })
        const my = Api.getMyAnnotationList({
            slideId: val,
            page: 1,
            pageCnt: 1000
        })
        const [preRes, myRes] = await Promise.all([pre, my])
        const list = [...preRes.data.list, ...myRes.data.list]
        annotationList.value = list.map(item => JSON.parse(item.content))
        
    })
    if(id) slideId.value = id

    return {
        slideId,
        annotationList
    }
}